package main

import (
	"flag"
	"fmt"
	"log"

	"gitee.com/xuender/images"
)

func main() {
	flag.Parse()

	if argLen := 2; flag.NArg() < argLen {
		usage()
		log.Fatal("缺少参数")
	}

	s, err := images.Decode(flag.Arg(0))
	if err != nil {
		log.Fatal(flag.Arg(0), err)
	}

	if err := images.Save(images.ToGray(s), flag.Arg(1)); err != nil {
		log.Fatal(err)
	}

	log.Println("保存图片: ", flag.Arg(1))
}

func usage() {
	fmt.Fprintln(flag.CommandLine.Output(), "Usage of gray: 图像灰度转换")
	fmt.Fprintln(flag.CommandLine.Output(), "\tgray 目标图片 灰度图片")

	flag.PrintDefaults()
}
